{"id":1227,"date":"2025-01-12T20:52:13","date_gmt":"2025-01-13T01:52:13","guid":{"rendered":"https:\/\/www.oopus.info\/blog\/?p=1227"},"modified":"2025-01-12T20:56:27","modified_gmt":"2025-01-13T01:56:27","slug":"nextjs-ssg-rust-web-server","status":"publish","type":"post","link":"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/","title":{"rendered":"nextjs SSG + rust web server"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Create components for specific hooks<\/h2>\n\n\n\n<p>If there are some special hooks were used, for example <code>useSearchParams()<\/code>, wrap it as a component, using suspense to load it. Ex:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { Suspense } from 'react';\nimport ChatComponent from '.\/ChatComponent';\n\nexport default function Page() {\n return (\n  &lt;div className=\"font-sans max-w-3xl mx-auto p-5\">\n    &lt;h1 className=\"text-2xl font-bold mb-4 text-center\">Yidam Chat&lt;\/h1>\n    &lt;Suspense fallback={&lt;div>Loading chat...&lt;\/div>}>\n     &lt;ChatComponent \/>\n    &lt;\/Suspense>\n  &lt;\/div>\n );\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Set next.config.ts<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import type { NextConfig } from \"next\";\n\nconst nextConfig: NextConfig = {\n \/* config options here *\/\n reactStrictMode: true,\n output: 'export',\n basePath: '\/web',\n};\n\nexport default nextConfig;<\/code><\/pre>\n\n\n\n<p><strong>Notes<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set <code>output: 'export'<\/code> for <code>npm run build<\/code><\/li>\n\n\n\n<li>Set <code>basePath: '\/web'<\/code> for the sub-directory of the web root<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Set package.json<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code> \"scripts\": {\n  \"dev\": \"next dev\",\n  \"build\": \"next build\",\n  \"start\": \"next start\",\n  \"lint\": \"next lint\"\n },<\/code><\/pre>\n\n\n\n<p>Notes: just keep as it was<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Run command to generate files<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>npm run build<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">(Optional) Rust web server setting<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>use axum::{\n  routing::{get, get_service},\n  Router,\n};\n\nasync fn main() {\n  let state = Arc::new(AppState {\n    context: Mutex::new(Vec::new()),\n  });\n\n  let app = Router::new()\n  .route(\"\/ws\", get(websocket_handler))\n  .nest_service(\"\/web\", get_service(ServeDir::new(\".\/src\/web\")))\n  .with_state(state);\n  const PORT: u16 = 3001;\n  \/\/ get lan ip\n  let listener = tokio::net::TcpListener::bind(format!(\"0.0.0.0:{}\", PORT)).await.unwrap();\n  println!(\"Please open http:\/\/{}:{}\/web\", get_local_ip().unwrap(), PORT);\n  axum::serve(listener, app).await.unwrap();\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Create components for specific hooks If there are some special hooks were used, for example useSearchParams(), wrap it as a component, using suspense to load it. Ex: Set next.config.ts Notes Set package.json Notes: just keep as it was Run command to generate files (Optional) Rust web server setting<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1227","post","type-post","status-publish","format-standard","hentry","category-computer-science"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>nextjs SSG + rust web server - Oopus Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"nextjs SSG + rust web server - Oopus Blog\" \/>\n<meta property=\"og:description\" content=\"Create components for specific hooks If there are some special hooks were used, for example useSearchParams(), wrap it as a component, using suspense to load it. Ex: Set next.config.ts Notes Set package.json Notes: just keep as it was Run command to generate files (Optional) Rust web server setting\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/\" \/>\n<meta property=\"og:site_name\" content=\"Oopus Blog\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-13T01:52:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-13T01:56:27+00:00\" \/>\n<meta name=\"author\" content=\"oopus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"oopus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/\"},\"author\":{\"name\":\"oopus\",\"@id\":\"https:\/\/www.oopus.info\/blog\/#\/schema\/person\/0491ca0bc5ba1f23b62bb7be621f29c9\"},\"headline\":\"nextjs SSG + rust web server\",\"datePublished\":\"2025-01-13T01:52:13+00:00\",\"dateModified\":\"2025-01-13T01:56:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/\"},\"wordCount\":65,\"articleSection\":[\"computer science\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/\",\"url\":\"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/\",\"name\":\"nextjs SSG + rust web server - Oopus Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.oopus.info\/blog\/#website\"},\"datePublished\":\"2025-01-13T01:52:13+00:00\",\"dateModified\":\"2025-01-13T01:56:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.oopus.info\/blog\/#\/schema\/person\/0491ca0bc5ba1f23b62bb7be621f29c9\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.oopus.info\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"nextjs SSG + rust web server\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.oopus.info\/blog\/#website\",\"url\":\"https:\/\/www.oopus.info\/blog\/\",\"name\":\"Oopus Blog\",\"description\":\"Oopu&#039;s self-recording\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.oopus.info\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.oopus.info\/blog\/#\/schema\/person\/0491ca0bc5ba1f23b62bb7be621f29c9\",\"name\":\"oopus\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/e6169b542ea65ef728fae42c117aa13b4897842f8263161765d1384a2a6e6fd9?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e6169b542ea65ef728fae42c117aa13b4897842f8263161765d1384a2a6e6fd9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e6169b542ea65ef728fae42c117aa13b4897842f8263161765d1384a2a6e6fd9?s=96&d=mm&r=g\",\"caption\":\"oopus\"},\"sameAs\":[\"http:\/\/www.oopus.info\/blog\"],\"url\":\"https:\/\/www.oopus.info\/blog\/author\/oopus\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"nextjs SSG + rust web server - Oopus Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/","og_locale":"en_US","og_type":"article","og_title":"nextjs SSG + rust web server - Oopus Blog","og_description":"Create components for specific hooks If there are some special hooks were used, for example useSearchParams(), wrap it as a component, using suspense to load it. Ex: Set next.config.ts Notes Set package.json Notes: just keep as it was Run command to generate files (Optional) Rust web server setting","og_url":"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/","og_site_name":"Oopus Blog","article_published_time":"2025-01-13T01:52:13+00:00","article_modified_time":"2025-01-13T01:56:27+00:00","author":"oopus","twitter_card":"summary_large_image","twitter_misc":{"Written by":"oopus","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/#article","isPartOf":{"@id":"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/"},"author":{"name":"oopus","@id":"https:\/\/www.oopus.info\/blog\/#\/schema\/person\/0491ca0bc5ba1f23b62bb7be621f29c9"},"headline":"nextjs SSG + rust web server","datePublished":"2025-01-13T01:52:13+00:00","dateModified":"2025-01-13T01:56:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/"},"wordCount":65,"articleSection":["computer science"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/","url":"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/","name":"nextjs SSG + rust web server - Oopus Blog","isPartOf":{"@id":"https:\/\/www.oopus.info\/blog\/#website"},"datePublished":"2025-01-13T01:52:13+00:00","dateModified":"2025-01-13T01:56:27+00:00","author":{"@id":"https:\/\/www.oopus.info\/blog\/#\/schema\/person\/0491ca0bc5ba1f23b62bb7be621f29c9"},"breadcrumb":{"@id":"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.oopus.info\/blog\/2025\/01\/12\/nextjs-ssg-rust-web-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.oopus.info\/blog\/"},{"@type":"ListItem","position":2,"name":"nextjs SSG + rust web server"}]},{"@type":"WebSite","@id":"https:\/\/www.oopus.info\/blog\/#website","url":"https:\/\/www.oopus.info\/blog\/","name":"Oopus Blog","description":"Oopu&#039;s self-recording","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.oopus.info\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.oopus.info\/blog\/#\/schema\/person\/0491ca0bc5ba1f23b62bb7be621f29c9","name":"oopus","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e6169b542ea65ef728fae42c117aa13b4897842f8263161765d1384a2a6e6fd9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e6169b542ea65ef728fae42c117aa13b4897842f8263161765d1384a2a6e6fd9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e6169b542ea65ef728fae42c117aa13b4897842f8263161765d1384a2a6e6fd9?s=96&d=mm&r=g","caption":"oopus"},"sameAs":["http:\/\/www.oopus.info\/blog"],"url":"https:\/\/www.oopus.info\/blog\/author\/oopus\/"}]}},"_links":{"self":[{"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/posts\/1227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/comments?post=1227"}],"version-history":[{"count":4,"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/posts\/1227\/revisions"}],"predecessor-version":[{"id":1232,"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/posts\/1227\/revisions\/1232"}],"wp:attachment":[{"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/media?parent=1227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/categories?post=1227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/tags?post=1227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}